<?php
/*---------------------------------------根据别名获取url---------------------*/
function get_url_from_name($name){
  $cat=get_category_by_slug($name); //获取分类别名为 wordpress 的分类数据 
  $cat_links=get_category_link($cat->term_id); // 通过$cat数组里面的分类id获取分类链接  
  echo $cat_links;  
}

// //修改WordPress 搜索结果页面url 形式    devework.com
// function redirect_search() {
//   if (is_search() && !empty($_GET['s'])) {
//     wp_redirect(home_url("/?cat=1/").urlencode(get_query_var('s')));
//     exit();
//   }
// }
// add_action('template_redirect', 'redirect_search' );
/*-------------------------------wordPress 添加id------------------*/


// 添加一个新的列 ID
function ssid_column($cols) {
$cols['ssid'] = 'ID';
return $cols;
}
// 显示 ID
function ssid_value($column_name, $id) {
if ($column_name == 'ssid')
echo $id;
}
function ssid_return_value($value, $column_name, $id) {
if ($column_name == 'ssid')
$value = $id;
return $value;
}
// 为 ID 这列添加css
function ssid_css() {
?>
<style type="text/css">
#ssid { width: 50px; } /* Simply Show IDs */
</style>
<?php
}
// 通过动作、过滤器输出各种表格和CSS
function ssid_add() {
add_action('admin_head', 'ssid_css');
add_filter('manage_posts_columns', 'ssid_column');
add_action('manage_posts_custom_column', 'ssid_value', 10, 2);
add_filter('manage_pages_columns', 'ssid_column');
add_action('manage_pages_custom_column', 'ssid_value', 10, 2);
add_filter('manage_media_columns', 'ssid_column');
add_action('manage_media_custom_column', 'ssid_value', 10, 2);
add_filter('manage_link-manager_columns', 'ssid_column');
add_action('manage_link_custom_column', 'ssid_value', 10, 2);
add_action('manage_edit-link-categories_columns', 'ssid_column');
add_filter('manage_link_categories_custom_column', 'ssid_return_value', 10, 3);
foreach ( get_taxonomies() as $taxonomy ) {
add_action("manage_edit-${taxonomy}_columns", 'ssid_column');
add_filter("manage_${taxonomy}_custom_column", 'ssid_return_value', 10, 3);

}
add_action('manage_users_columns', 'ssid_column');
add_filter('manage_users_custom_column', 'ssid_return_value', 10, 3);
add_action('manage_edit-comments_columns', 'ssid_column');
add_action('manage_comments_custom_column', 'ssid_value', 10, 2);
}
add_action('admin_init', 'ssid_add');
?>
